from django import forms
from django.shortcuts import render_to_response, redirect
import logging
from django.views.decorators.csrf import csrf_exempt

class LoginForm(forms.Form):
    login = forms.CharField(required = True)
    password = forms.CharField(required = True)
    def clean(self):
		login = self.cleaned_data['login']
		password = self.cleaned_data['password']
		if login != password:
			raise forms.ValidationError(u'Wrong authentication data.' )
		return True
		
@csrf_exempt		
def LoginAction(request):
	if request.method == 'POST':
		form = LoginForm(request.POST)
		if not form.is_valid():
			return render_to_response('login.html', {'form': form})
		else:
			redirect('/')
	else:
		form = LoginForm()
		return render_to_response('login.html', {'form': form})
